from dc_shop.core.models.dto.cart import CartDTO, CartLineDTO
from dc_shop.database.models import Cart, CartProduct


def convert_db_model_to_cartlines_dto(line: CartProduct) -> CartLineDTO:
    return CartLineDTO(product_id=line.product_id, quantity=line.quantity)


def convert_db_model_to_cart_dto(cart: Cart) -> CartDTO:
    cart_lines = [convert_db_model_to_cartlines_dto(line) for line in cart.products]

    return CartDTO(id=cart.id, products=cart_lines, user_id=cart.user_id)
